const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin")
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
    //运行时写--config
    mode: "production",
    entry: path.resolve(process.cwd(), './src'),
    output: {
        path: path.resolve(process.cwd(), "./dist"),
        filename: "main.js",
        publicPath: '/'
    },
    resolve: {
        alias: {
            "@": path.resolve(process.cwd(), "src/views")
        }
    },
    module: {
        rules: [{
            test: /\.html$/i,
            loader: "html-loader",
        },
        {
            test: /\.ejs$/,
            loader: 'ejs-loader',
            options: {
                variable: 'data', // 可以在模块当中使用data进行数据处理
            }
        }],
    },
    plugins: [
        // 根据模板html生成测试html
        new HtmlWebpackPlugin({
            title: "App",
            filename: "index.html",
            template: "./public/index.html"
        }),
        new CopyWebpackPlugin({
            // 将public文件夹中的所有文件不编译直接复制到出口文件夹
            patterns: [{
                from: "public",
                to: "./",
                globOptions: {
                    ignore: ["**/index.html"] // 排除index.html
                }
            }, {
                // 复制静态文件传入到出口中
                from: "./src/static",
                to: "./"
            }]
        })
    ]
}